{% extends "base/base.html" %}
{% block content %}

<script type="text/javascript">

   // Date
   $(function() {

      $("#jump_to").datepicker({dateFormat: 'yy-mm-dd'});

   });

</script>

<div class="wrapper">
<table class="top">
 <tr>
  <td colspan="2" style="text-align:left;">
   <p class="title">System Status Dashboard</p>
  </td>
 </tr>
 <tr>
  <td colspan="2" height="15">
 </tr>

 {% if not maintenance.0.config_value == 'none' %}
 <tr>
  <td colspan="2" style="text-align:center;">
   <center>
    <div class="maintenance">
     {{maintenance.0.config_value}}
    </center>
   </div> 
  </td>
 </tr>
 <tr>
  <td colspan="2" height="25"></td> 
 </tr>
 {% endif %}

 <tr>
  <td colspan="2">
   <table class="standard">
   {% for row in data %}
     {% if forloop.first %}
       <tr>
        {% for heading in row %}
         {% if forloop.first %}
          <th>{{heading}}</th>
         {% else %}
          <th>{{heading|date:"Y-m-d"}}<br>{{heading|date:"D"}}</th>
         {% endif %}
        {% endfor %}
       </tr>
     {% else %}
      <tr>
       {% for row1 in row %}
         {% if forloop.first %}
           <td>
           {% if row1 in impaired_services %}
           <img src="/html/images/incident_red.png">
           {% else %}
           <img src="/html/images/incident_green.png">
           {% endif %}
           {{row1}}
           </td>
         {% else %}
           <td style="text-align:center;">
           {% for row2 in row1 %}
             {% if not row2 == 'green' %}

              {# See if the incident is open or closed.  No way to break out of a loop here but there will be only a single match #}
              {% for incident,detail in incident_status.items %}
               {% if incident == row2 %} 
                {% if detail.closed == None %}
                 <a href="/detail?id={{row2}}"><img src="/html/images/incident_red.png" title="ID: {{row2}} : {{detail.open|date:"Y-m-d H:i:s"}} ~"></a>
                {% else %}
                 <a href="/detail?id={{row2}}"><img src="/html/images/incident_orange.png" title="ID: {{row2}} : {{detail.open|date:"Y-m-d H:i:s"}} ~ {{detail.closed|date:"Y-m-d H:i:s"}}"></a>
                {% endif %}
               {% endif %}
              {% endfor %}

             {% endif %}
           {% endfor %}
           </td>
         {% endif %}
       {% endfor %}
      </tr>
     {% endif %}
   {% endfor %}
   </table>
  </td>
 </tr>
 
 <tr>
  <td colspan="2" height="5"></td>
 </tr>

 <tr>
  <td style="text-align:left;">
   <table>
    <tr>
     <td><img src="/html/images/incident_green.png"></td>
     <td>Service Normal</td>
     <td><img src="/html/images/incident_red.png"></td>
     <td>Service Disruption</td>
     <td><img src="/html/images/incident_orange.png"></td>
     <td>Service Disruption (resolved)</td>
    </tr>
   </table>
  </td>
  <td style="text-align:right;">
   {% if backward_link %}
   <a href="{{backward_link}}"><<< older</a>
   {% endif %}
   {% if forward_link %}
   <a href="{{forward_link}}">newer >>></a>
   {% endif %}
  </td>
 </tr>

 <tr>
  <td style="text-align:left;">
   <table>
    <tr>
     <td>Timezone:</td>
     <td>
      <form name="prefs_timezone" id="prefs_timezone" action="/prefs/timezone" method="post" style="margin: 0px; padding: 0px;">
       {% csrf_token %}
       <select class="timezone" name="timezone" id="timezone" onchange='this.form.submit()'>
       {% for timezone in timezones %}
        {% if timezone == TIME_ZONE %}
         <option value="{{timezone}}" selected="true">{{timezone}}</option>
        {% else %}
         <option value="{{timezone}}">{{timezone}}</option>
        {% endif %}
       {% endfor %}
       </select>
      </form>
     </td>
     <td width="10"></td>
     <td>Jump To:</td>
     <td>
      <form name="prefs_jump" id="prefs_jump" action="/prefs/jump" method="post" style="margin: 0px; padding: 0px;">
       {% csrf_token %}
      <input type="text" class="jump_to" name="jump_to" id="jump_to" value="" onchange='this.form.submit()'/>
      </form>
     </td>
    </tr>
   </table>
  </td>
  <td style="text-align:right;">
   {% if app_version %}
   <a href="http://www.system-status-dashboard.com">SSD</a> v{{app_version}}
   {% endif %}
  </td>
 </tr>

</table>

</div>

{% endblock %}
